class YSHCommonMealModel {
  late final String? id;
  late final List<String>? categories;
  late final String? title;
  late final int? affordability;
  late final int? complexity;
  late final String? complexityStr;
  late final String? imageUrl;
  late final int? duration;
  late final List<String>? ingredients;
  late final List<String>? steps;
  late final bool? isGlutenFree;
  late final bool? isVegan;
  late final bool? isVegetarian;
  late final bool? isLactoseFree;

  YSHCommonMealModel(
      {this.id,
        this.categories,
        this.title,
        this.affordability,
        this.complexity,
        this.complexityStr,
        this.imageUrl,
        this.duration,
        this.ingredients,
        this.steps,
        this.isGlutenFree,
        this.isVegan,
        this.isVegetarian,
        this.isLactoseFree
      }
  );

  factory YSHCommonMealModel.fromMap(Map<String, dynamic> map) => YSHCommonMealModel(
    id: map["id"],
    categories: List<String>.from(map["categories"].map((x) => x)),
    title: map["title"],
    affordability: map["affordability"],
    complexity: map["complexity"],
    complexityStr: YSHCommonMealModel.convertComplexity(map["complexity"] as int),
    imageUrl: map["imageUrl"],
    duration: map["duration"],
    ingredients: List<String>.from(map["ingredients"].map((x) => x)),
    steps: List<String>.from(map["steps"].map((x) => x)),
    isGlutenFree: map["isGlutenFree"],
    isVegan: map["isVegan"],
    isVegetarian: map["isVegetarian"],
    isLactoseFree: map["isLactoseFree"],
  );

  Map<String, dynamic> toMap() => {
    "id": id,
    "categories": categories != null
        ? List<dynamic>.from(categories!.map((x) => x))
        : '',
    "title": title,
    "affordability": affordability,
    "complexity": complexity,
    "complexityStr": complexityStr,
    "imageUrl": imageUrl,
    "duration": duration,
    "ingredients": ingredients != null
        ? List<dynamic>.from(ingredients!.map((x) => x))
        : '',
    "steps": steps != null ? List<dynamic>.from(steps!.map((x) => x)) : '',
    "isGlutenFree": isGlutenFree,
    "isVegan": isVegan,
    "isVegetarian": isVegetarian,
    "isLactoseFree": isLactoseFree,
  };

  @override
  String toString() {
    return '''
    YshMealModel{
    id: $id, 
    categories: $categories, 
    title: $title, 
    affordability: $affordability, 
    complexity: $complexity, complexityStr: $complexityStr, 
    imageUrl: $imageUrl, 
    duration: $duration, 
    ingredients: $ingredients, 
    steps: $steps, 
    isGlutenFree: $isGlutenFree, 
    isVegan: $isVegan, 
    isVegetarian: $isVegetarian, 
    isLactoseFree: $isLactoseFree}
    ''';
  }

  static String convertComplexity(int complexity) {
    if (complexity == 0) {
      return '简单';
    } else if (complexity == 1) {
      return '中等';
    } else if (complexity == 2) {
      return '困难';
    } else {
      return '--';
    }
  }

}
